#pragma once

#include "LinkedList.h"

struct BufChunk
{
    unsigned int nLength;
    void *pStart;
    void *pEnd;
    void *pCurPos;
};

typedef CLinkedList<BufChunk, CSpinLock> CBufChunkList;
typedef CBufChunkList::Node BufChunkNode;

class CBufChunkMgr
{
public:
    CBufChunkMgr();
    ~CBufChunkMgr();
    void *operator new(size_t sz);
    void operator delete(void *ptr);
    void Destroy();

    void *Alloc(unsigned int nLen);

private:
    BufChunkNode *NewChunk();
    void DeleteChunk(BufChunkNode *pNode);

    BufChunkNode *AddNewChunk();

private:
    CBufChunkList m_lstChunk;
};
